package com.cx.healthex.client.wechat.dao;

import java.util.ArrayList;
import java.util.List;

import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import com.cx.base.apiModel.PageModel;
import com.cx.base.dao.BaseDAO;
import com.cx.base.utils.StringUtil;
import com.cx.healthex.client.wechat.dto.consumer.ConsumerDTO;
import com.cx.healthex.client.wechat.utils.external.MD5Util;

@Repository
public class ConsumerDAO extends BaseDAO{

	/**
	 * 查询客户
	 * */
	public ConsumerDTO queryConsumerByphoneAndPwd(String phone,String password){
		//不能为空
		if(StringUtil.isNotNull(phone) && StringUtil.isNotNull(password)){
			String sql = " select * from iat_consumer where phone = ? and password = ? ";
			List<Object> parameter = new ArrayList<Object>();
			parameter.add(phone);
			//加密处理
			parameter.add(MD5Util.getMD5Str(password));
			
			PageModel<ConsumerDTO> pageModel = getPageList(1, 1, sql, parameter.toArray(), ParameterizedBeanPropertyRowMapper.newInstance(ConsumerDTO.class));
			
			if(pageModel != null && pageModel.getItems() != null && pageModel.getItems().size() > 0){
				return pageModel.getItems().get(0);
			}
		}
		return null;
	}
}
